/**
 * 
 */
package core.proto;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

/**
 * @author poornima
 * 
 */
public class CommentHandler extends JDialog {

	private JTextArea textArea;
	private String commentText;

	public String getCommentText() {
		return this.commentText;
	}

	public void setCommentText(String commentText) {
		this.commentText = commentText;
	}

	public CommentHandler() {
		init();
	}

	public CommentHandler(String comment) {
		commentText = comment;
		init();
	}

	public void showCommentBox() {
		setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));

		add(Box.createRigidArea(new Dimension(0, 10)));

		textArea = new JTextArea(commentText);
		JScrollPane textScroller = new JScrollPane(textArea);
		textScroller.setVisible(true);
		add(textScroller);
		add(Box.createRigidArea(new Dimension(0, 10)));

		JButton save = new JButton("Save");
		save.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent event) {
				commentText = textArea.getText();
				dispose();
			}
		});

		add(save);
		add(Box.createRigidArea(new Dimension(10, 0)));

		JButton cancel = new JButton("Cancel");
		cancel.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent event) {
				dispose();
			}
		});

		add(cancel);

		setModalityType(ModalityType.APPLICATION_MODAL);

		setTitle("Enter your comments:");
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		setLocationRelativeTo(null);
		setSize(300, 200);
	}

	private final void init() {
		showCommentBox();
	}
}